<?php

class Pages_Form_Node extends Zend_Form {

	public function init() {
		$this->setMethod('post');
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		$defaultLang = key($locales);
		
		$subFormTitle = new Zend_Form_SubForm();
        $subFormTitle->removeDecorator('Fieldset');
        $subFormContent = new Zend_Form_SubForm();
        $subFormContent->removeDecorator('Fieldset');
        
        foreach($locales as $lang=>$value) {
        	$title = new Zend_Form_Element_Text($lang);
        	$title->setLabel(strtoupper($lang) . ' ' . _('Title:'));
        	$title->setAttrib('maxlength', '255');
        	$title->addFilters(array('StringTrim','StripTags'));
        	
        	$content = new ZFEngine_Form_Element_TinyMce($lang);
			$content->setLabel(strtoupper($lang) . ' ' . _('Content of node:'));
			$content->setAttrib('editorOptions', array('theme' => 'advanced'));
			$content->setFilters(array('StringTrim'));
			
			if($defaultLang == $lang) {
				$title->setRequired(true);
				$content->setRequired(true);
			}
			
			$subFormTitle->addElement($title);
			$subFormContent->addElement($content);
        }
        
        $this->addSubForm($subFormTitle, 'title');
		$this->addSubForm($subFormContent, 'content');
		
		$page_id = $this->createElement('select', 'page_id');
		$page_id->setLabel(_('Page:'));
		$page_id->setRequired(true);
		$this->addElement($page_id);
		
		$submit = $this->createElement('submit', 'submit');
		$submit->setLabel(_('Save'));
		
		$this->addElement($submit);
	}
}